<template>
  <header class="navbar">
    <div class="upper" v-if="isUpper" @click="goto">
      <i class="iconfont icon-zuojiantou"></i>
    </div>
    <div class="content">
      <div class="text">
        <slot name="text"></slot>
      </div>
      <slot name="extra"></slot>
    </div>
    <div class="icon">
      <slot name="icon"></slot>
    </div>
  </header>
</template>

<script>
import { mapState, mapActions } from 'vuex';

export default {
  props: {
    isUpper: {
      type: Boolean,
      default: true
    },
    isSearch: {
      type: Boolean,
      default: false
    },
    isAddress: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {};
  },
  computed: {
    ...mapState(['userInfo'])
  },
  mounted() {
    if (!(this.userInfo && this.userInfo.id)) {
      this.getUserInfo();
    }
  },
  methods: {
    ...mapActions(['getUserInfo']),
    goto() {
      if (this.path) {
        this.$router.push(this.path);
      } else {
        this.$router.go(-1);
      }
    }
  }
};
</script>

<style lang="less" scoped>
.navbar {
  position: fixed;
  width: 100%;
  height: 45px;
  line-height: 45px;
  padding: 0 20px;
  z-index: 99;
  background-color: var(--color-base);
  .upper,
  .icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    i {
      font-size: 20px;
      color: #fff;
    }
  }
  .upper {
    left: 10px;
  }
  .icon {
    right: 10px;
  }
  .content {
    text-align: center;
    color: #fff;
  }
}
</style>
